"""
PyMySQL访问数据库 - 更新数据
"""
import pymysql
import common

no = int(input('学号: '))
name = input('姓名: ')
addr = input('家庭住址: ')
col = input('学院编号： ')
conn = common.get_conn(database='school')
try:
    with conn.cursor() as cursor:
        result = cursor.execute(
            'update tb_student set stuname=%s, stuaddr=%s, collid=%s '
            'where stuid=%s', (name, addr, col, no)
        )
        print('更新成功!!!' if result == 1 else '没有该学生!!!')
    conn.commit()
except pymysql.MySQLError as err:
    conn.rollback()
    print(err, '更新失败!!!')
finally:
    conn.close()